//
// File:	EntityFactory.hpp
// Author:	Thomas TISSOT-DUPONT
// Login:	<thomas.tissotdupont@free.fr>
//
// Create:	27/01/2010 at 17:55:56
// Purpose:	
//
#ifndef ENTITYFACTORY_HPP
#define ENTITYFACTORY_HPP

#include <map>
#include <string>
#include "Base.hpp"
#include "IEntity.hpp"
#include "IEntityFactory.hpp"

//------------------------------------------------------------------
// Helpers Macros
//------------------------------------------------------------------
#define LINK_ENTITY_TO_CLASS(name, cppname)			GlobalVariables::EntityManager::Get().GetEntityFactory()->RegisterEntityClass(#name, &cppname::Create)
#define DECLARE_ENTITY(cppname)						public:															\
														static IEntity *Create(const std::string &classname)		\
														{															\
															IEntity *pEntity = new cppname();						\
															if (pEntity) pEntity->SetClassname(classname);			\
															return pEntity;											\
														}

//------------------------------------------------------------------
// Entity Factory Class
//------------------------------------------------------------------
class EntityFactory : public IEntityFactory
{
public:
												EntityFactory();
												~EntityFactory();

public:
	bool										RegisterEntityClass(const std::string &, tPfnEntityCreate);
	IEntity										*CreateEntityByName(const std::string &, const tEntityDatamapKeyValues * = NULL);

private:
	std::map<std::string, tPfnEntityCreate>		m_dictionary;
};

#endif //!ENTITYFACTORY_HPP
